package com.liufh.controller;

import com.liufh.common.ResultData;
import com.liufh.entity.MailReq;
import com.liufh.service.MailService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;

/**
 * @author: liufh
 * @create: 2022-01-21 09:54
 **/
@RestController
@RequestMapping("/api/email")
@CrossOrigin
@Slf4j
public class EmailController {

    @Autowired
    private MailService mailService ;

    /**
     * 发送验证码到邮箱
     */
    @PostMapping("/{email}/{code}")
    public ResultData email(@PathVariable("email") String email, @PathVariable("code") String code, HttpServletResponse response) throws Exception {
        System.out.println("====email:" + email + ",code:" + code);

        MailReq MailReq = new MailReq();
        MailReq.setTo(email);
        MailReq.setSubject("验证码发送");
        MailReq.setText(code);
//        if (multipartFiles.length > 0){
//            MailReq.setMultipartFiles(multipartFiles);
//        }

        com.liufh.entity.MailReq mailReq1 = mailService.sendMail(MailReq);
        System.out.println(mailReq1);

        return ResultData.success(response, "ok", "success", "0");
    }

}
